#![no_std]
#![no_main]

use cmsis_rtos2_rs::{os_kernel_initialize, os_kernel_start};
use embedded_alloc::LlffHeap as Heap;
use periph_utils::{afio::set_swj, entry, pre_init, rcc::set_sys_clock_to72};
use utils::ByteBuffer;
use periph_utils as _;

#[cfg(feature = "base_app")]
extern crate alloc;

mod error;

mod address;

mod driver;

#[cfg(feature = "base_app")]
mod conn;


mod task;

#[cfg(feature = "base_app")]
mod cmd;

#[cfg(feature = "cp_drop")]
mod cp_drop;

#[cfg(feature = "cp_cargo")]
mod cp_cargo;

#[cfg(feature = "cp_door")]
mod cp_door;

#[cfg(feature = "cp_heat")]
mod cp_heat;

#[cfg(feature = "cp_weight")]
mod cp_weight;

#[global_allocator]
static HEAP: Heap = Heap::empty();

fn init_heap() {
    const HEAP_SIZE: usize = 5 * 1024;
    static HEAP_MEM: ByteBuffer<HEAP_SIZE> = ByteBuffer::const_new();
    unsafe {
        HEAP.init(HEAP_MEM.as_ptr() as _, HEAP_MEM.size());
    }
}

#[pre_init]
unsafe fn init() {
    set_sys_clock_to72();
}

#[entry]
unsafe fn main() -> ! {
    init_heap();
    set_swj();
    os_kernel_initialize();
    task::start();
    os_kernel_start();
    loop {}
}


